import { Adapter } from "../adapter/adapter";
import { App_Interface } from "./app_interface";


export class App_Framework implements App_Interface.IFramework
{
    userCode: App_Interface.IUserCode;
    render: Adapter.IRenderAdapter | null;
    audio: Adapter.IAudioAdapter | null;
    constructor(userCode: App_Interface.IUserCode, render: Adapter.IRenderAdapter | null, audio: Adapter.IAudioAdapter | null)
    {
        this.userCode = userCode;
        this.render = render;
        this.audio = audio;
    }
    public async Init(): Promise<void>
    {
        await this.userCode.OnInit(this);

        requestAnimationFrame(() =>
        {
            this.Update();
        });
    }
    public Update(): void
    {
        this.render?.Clear();

        this.userCode.OnUpdate(this);
        requestAnimationFrame(() =>
        {
            this.Update();
        });

    }
}

